package com.powersystem.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powersystem.demo.entity.PsRole;
import com.powersystem.demo.service.IPsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.management.relation.RoleInfo;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author linrongji
 * @since 2019-11-14
 */
@RestController
public class PsRoleController {
    @Autowired
    private IPsRoleService  ipsRoleService;
    @RequestMapping("roleInfo")
    // 显示角色列表所有数据
    public Map<String,Object> getRoleInfo(){
        Map<String,Object> roleInfo = new HashMap<String,Object>();
        IPage<PsRole> page = new Page<>(0, 4);
        QueryWrapper<PsRole> wrapper = new QueryWrapper<>();
        roleInfo.put("roleInfo",ipsRoleService.page(page,wrapper));
        return roleInfo;
    }

    @RequestMapping("fetchByRoleInfo")
    // 判断用户是否存在
    public boolean fetchByUserName(String roleId,String roleName){
        return ipsRoleService.fetchByRoleIdAndRoelName(roleId,roleName) == null;
    }
    @RequestMapping("addRoleInfo")
    public boolean addRoleInfo(PsRole psRole){
        return ipsRoleService.save(psRole);
    }
    @RequestMapping("updateRoleInfo")
    //根据id 更新
    public  boolean updateRoleInfo(PsRole psRole){
        return ipsRoleService.updateById(psRole);
    }
    @RequestMapping("removeRoleInfo")
    // 根据 id删除
    public boolean removeRoleInfo(PsRole psRole){
        return ipsRoleService.removeById(psRole.getId());
    }




}

